$(document).ready(function() {
      if ($('#lt-msie').length > 0) {
            var bkp = $('#lt-msie').clone();
            $('body').html('').append(bkp);
      } else {

            //Set the navigation bar.
            $('header a').each(function() {
                  $(this).bind('click touchstart', navigationBar);
            });

            $('#banner ul').cycle({
                  fx: 'fade',
                  speed: 250,
                  timeout: 3000,
                  prev: $('#toLeftBanner'),
                  next: $('#toRightBanner')
            });

            //Set thumb buttons.
            $('.thumb-container').each(function() {
                  $(this).bind('click touchstart', showCases);
            });

            //Set button close to thumb details.
            $('.btnX').each(function() {
                  $(this).bind('click touchstart', closeCases);
            });

            //Set the cycle to thumbs figures.
            $('figure ul').each(function() {
                  var parentElder = $(this).parents('div.sprite');
                  $(this).cycle({
                        fx: 'fade',
                        speed: 500,
                        timeout: 0,
                        prev: $('.toLeft', parentElder),
                        next: $('.toRight', parentElder)
                  });
            });
            
            window.trixterAnimation = new TrixterAnimation();
            window.trixterAnimation.init();
      }
});
/**
 * Show the figure of the current case.
 * @param {TouchEvent, MouseEvent} event
 * @returns {undefined}
 */
function showCases(event) {
      var target = $(event.target).parent().next();
      if ($('div.sprite.selected').length > 0) {
            $('div.sprite.selected').hide(500, function() {
                  $('div.sprite.selected').removeClass('selected');
                  target.show(500);
                  target.addClass('selected');
            });
      } else {
            target.show(500);
            target.addClass('selected');
      }
}

/**
 * Close the current figure.
 * @param {type} event
 * @returns {undefined}
 */
function closeCases(event) {
      var target = $(event.target).parents('div.sprite');
      target.hide(500);
      target.removeClass('selected');
}

/**
 * Navigate between sections.
 * @param {MouseEvent} event
 * @returns {false}
 */
function navigationBar(event) {
      //Make the selection.
      $('#js-header .selected').removeClass('selected');
      $(event.target).addClass('selected');
      gotoSection($(event.target).attr('href'), $(event.target).data('time'));
      return false;
}

/**
 * Go to selected section.
 * @param {string} id
 * @returns {undefined}
 */
function gotoSection(id, time) {
      time = time ? parseInt(time) : 1000;
      $('html, body').animate({
            scrollTop: $(id).offset().top
      }, time, function(){
            window.location.hash = id;
      });
}